package com.example.easyscript.controller.task;

import com.example.easyscript.common.page.Page;
import com.example.easyscript.entity.task.Task;
import com.example.easyscript.service.task.TaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author huzixian
 * @date 2023-03-08
 */
@Api(value = "TaskController", tags = "")
@Slf4j
@RestController
@RequestMapping(value = "/web/task")
public class TaskController {

    @Resource
    private TaskService taskService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页数量", defaultValue = "100")
    })
    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    public Page<List<Task>> page(@ApiIgnore Page page) {
        return taskService.getPage(page);
    }

    @ApiOperation("保存")
    @PostMapping("/save")
    public void save(@RequestBody Task task) {
        taskService.save(task);
    }

    @ApiOperation("修改")
    @PostMapping("update")
    public void update(@RequestBody Task task) {
        taskService.updateById(task);
    }

    @ApiOperation("批量删除")
    @PostMapping("delete/{id}")
    public void deleteBatch(@PathVariable Integer id) {
        taskService.removeById(id);
    }

}